#include "NodesOpcodes.h"
#include "Opcodes.h"
#include "NodeSession.h"

void NodesOpcodes::BuildOpcodeList()
{
#define STORE_OPCODE(opcode, type, process, handler) StoreOpcode(opcode, #opcode, type, process, handler)
    STORE_OPCODE(MMSG_HELLO,                    FROM_MASTER,NODE_PROCESS_REALTIME,      &NodeSession::HandleMasterHello);
    STORE_OPCODE(NMSG_HELLO,                    FROM_NODE,  NODE_PROCESS_REALTIME,      &NodeSession::HandleNodeHello);
    STORE_OPCODE(NMSG_REQUEST_FREE_GUIDS_ITEMS, FROM_NODE,  NODE_PROCESS_REALTIME,      &NodeSession::HandleRequestFreeGuidsItems);
    STORE_OPCODE(NMSG_REQUEST_FREE_GUIDS_PETS,  FROM_NODE,  NODE_PROCESS_REALTIME,      &NodeSession::HandleRequestFreeGuidsPets);
    STORE_OPCODE(MMSG_ADD_FREE_GUIDS_ITEMS,     FROM_MASTER,NODE_PROCESS_REALTIME,      &NodeSession::HandleAddFreeGuidsItems);
    STORE_OPCODE(MMSG_ADD_FREE_GUIDS_PETS,      FROM_MASTER,NODE_PROCESS_REALTIME,      &NodeSession::HandleAddFreeGuidsPets);
    STORE_OPCODE(NMSG_SEND_PACKET_TO_CLIENT,    FROM_NODE,  NODE_PROCESS_REALTIME,      &NodeSession::HandleSendPacketToSession);
    STORE_OPCODE(MSG_FORWARD_CLIENT_PACKET,     BOTH,       NODE_PROCESS_REALTIME,      &NodeSession::HandleForwardClientPacket);
    STORE_OPCODE(MMSG_LOAD_SESSION,             FROM_MASTER,NODE_PROCESS_UNSAFE,        &NodeSession::HandleLoadSession);
    STORE_OPCODE(MMSG_LOAD_PLAYER_FROM_DB,      FROM_MASTER,NODE_PROCESS_UNSAFE,        &NodeSession::HandleLoadPlayerFromDB);
    STORE_OPCODE(MSG_LOAD_PLAYER_SERIALIZED,    BOTH,       NODE_PROCESS_UNSAFE,        &NodeSession::HandleLoadPlayerSerialized);
    STORE_OPCODE(MMSG_SESSION_SOCKET_LOST,      FROM_MASTER,NODE_PROCESS_UNSAFE,        &NodeSession::HandleSessionSocketClosed);
    STORE_OPCODE(NMSG_LOGOUT_COMPLETE,          FROM_NODE,  NODE_PROCESS_UNSAFE,        &NodeSession::HandleSessionLogoutComplete);

#define FWD_TO_NODE(opcode) mOpcodesToNode.insert(opcode)
    /*  To be handled Master side:
     * GM Tickets
     * Actions
     * Auctions
     * Mails
     * Tutorials
     */
    // Movement opcodes
    FWD_TO_NODE(MSG_MOVE_START_FORWARD);
    FWD_TO_NODE(MSG_MOVE_START_BACKWARD);
    FWD_TO_NODE(MSG_MOVE_STOP);
    FWD_TO_NODE(MSG_MOVE_START_STRAFE_LEFT);
    FWD_TO_NODE(MSG_MOVE_START_STRAFE_RIGHT);
    FWD_TO_NODE(MSG_MOVE_STOP_STRAFE);
    FWD_TO_NODE(MSG_MOVE_JUMP);
    FWD_TO_NODE(MSG_MOVE_START_TURN_LEFT);
    FWD_TO_NODE(MSG_MOVE_START_TURN_RIGHT);
    FWD_TO_NODE(MSG_MOVE_STOP_TURN);
    FWD_TO_NODE(MSG_MOVE_START_PITCH_UP);
    FWD_TO_NODE(MSG_MOVE_START_PITCH_DOWN);
    FWD_TO_NODE(MSG_MOVE_STOP_PITCH);
    FWD_TO_NODE(MSG_MOVE_SET_RUN_MODE);
    FWD_TO_NODE(MSG_MOVE_SET_WALK_MODE);
    FWD_TO_NODE(MSG_MOVE_TELEPORT_ACK);
    FWD_TO_NODE(MSG_MOVE_FALL_LAND);
    FWD_TO_NODE(MSG_MOVE_START_SWIM);
    FWD_TO_NODE(MSG_MOVE_STOP_SWIM);
    FWD_TO_NODE(MSG_MOVE_SET_FACING);
    FWD_TO_NODE(MSG_MOVE_SET_PITCH);
    FWD_TO_NODE(CMSG_FORCE_RUN_SPEED_CHANGE_ACK);
    FWD_TO_NODE(CMSG_FORCE_RUN_BACK_SPEED_CHANGE_ACK);
    FWD_TO_NODE(CMSG_FORCE_SWIM_SPEED_CHANGE_ACK);
    FWD_TO_NODE(CMSG_FORCE_MOVE_ROOT_ACK);
    FWD_TO_NODE(CMSG_FORCE_MOVE_UNROOT_ACK);
    FWD_TO_NODE(MSG_MOVE_HEARTBEAT);
    FWD_TO_NODE(CMSG_MOVE_KNOCK_BACK_ACK);
    FWD_TO_NODE(CMSG_MOVE_HOVER_ACK);
    FWD_TO_NODE(CMSG_MOVE_SPLINE_DONE);
    FWD_TO_NODE(CMSG_MOVE_FALL_RESET);
    FWD_TO_NODE(CMSG_MOVE_TIME_SKIPPED);
    FWD_TO_NODE(CMSG_MOVE_FEATHER_FALL_ACK);
    FWD_TO_NODE(CMSG_MOVE_WATER_WALK_ACK);
    FWD_TO_NODE(CMSG_MOVE_NOT_ACTIVE_MOVER);
    FWD_TO_NODE(CMSG_FORCE_WALK_SPEED_CHANGE_ACK);
    FWD_TO_NODE(CMSG_FORCE_SWIM_BACK_SPEED_CHANGE_ACK);
    FWD_TO_NODE(CMSG_FORCE_TURN_RATE_CHANGE_ACK);

    // Logout
    FWD_TO_NODE(CMSG_LOGOUT_CANCEL);
    FWD_TO_NODE(CMSG_PLAYER_LOGOUT);
    FWD_TO_NODE(CMSG_LOGOUT_REQUEST);

    // Mails - Handled MasterSide.
    //FWD_TO_NODE(CMSG_SEND_MAIL); // Sending mails from Node is currently not implemented
    //FWD_TO_NODE(MSG_QUERY_NEXT_MAIL_TIME);

    // Other opcodes
    FWD_TO_NODE(CMSG_USE_ITEM);
    FWD_TO_NODE(CMSG_OPEN_ITEM);
    FWD_TO_NODE(CMSG_READ_ITEM);
    FWD_TO_NODE(CMSG_GAMEOBJ_USE);
    FWD_TO_NODE(CMSG_AREATRIGGER);
    FWD_TO_NODE(CMSG_NEXT_CINEMATIC_CAMERA);
    FWD_TO_NODE(CMSG_COMPLETE_CINEMATIC);
    FWD_TO_NODE(CMSG_TUTORIAL_FLAG);
    FWD_TO_NODE(CMSG_TUTORIAL_CLEAR);
    FWD_TO_NODE(CMSG_TUTORIAL_RESET);
    FWD_TO_NODE(CMSG_STANDSTATECHANGE);
    FWD_TO_NODE(CMSG_EMOTE);
    FWD_TO_NODE(CMSG_TEXT_EMOTE);
    FWD_TO_NODE(CMSG_AUTOSTORE_LOOT_ITEM);
    FWD_TO_NODE(CMSG_AUTOEQUIP_ITEM);
    FWD_TO_NODE(CMSG_AUTOSTORE_BAG_ITEM);
    FWD_TO_NODE(CMSG_SWAP_ITEM);
    FWD_TO_NODE(CMSG_SWAP_INV_ITEM);
    FWD_TO_NODE(CMSG_SPLIT_ITEM);
    FWD_TO_NODE(CMSG_AUTOEQUIP_ITEM_SLOT);
    FWD_TO_NODE(CMSG_DESTROYITEM);
    FWD_TO_NODE(CMSG_INSPECT);
    FWD_TO_NODE(CMSG_INITIATE_TRADE);
    FWD_TO_NODE(CMSG_BEGIN_TRADE);
    FWD_TO_NODE(CMSG_BUSY_TRADE);
    FWD_TO_NODE(CMSG_IGNORE_TRADE);
    FWD_TO_NODE(CMSG_ACCEPT_TRADE);
    FWD_TO_NODE(CMSG_UNACCEPT_TRADE);
    FWD_TO_NODE(CMSG_CANCEL_TRADE);
    FWD_TO_NODE(CMSG_SET_TRADE_ITEM);
    FWD_TO_NODE(CMSG_CLEAR_TRADE_ITEM);
    FWD_TO_NODE(CMSG_SET_TRADE_GOLD);
    FWD_TO_NODE(CMSG_SET_FACTION_ATWAR);
    FWD_TO_NODE(CMSG_CAST_SPELL);
    FWD_TO_NODE(CMSG_CANCEL_CAST);
    FWD_TO_NODE(CMSG_CANCEL_AURA);
    FWD_TO_NODE(CMSG_CANCEL_CHANNELLING);
    FWD_TO_NODE(CMSG_SET_SELECTION);
    FWD_TO_NODE(CMSG_SET_TARGET_OBSOLETE);
    FWD_TO_NODE(CMSG_ATTACKSWING);
    FWD_TO_NODE(CMSG_ATTACKSTOP);
    FWD_TO_NODE(CMSG_REPOP_REQUEST);
    FWD_TO_NODE(CMSG_RESURRECT_RESPONSE);
    FWD_TO_NODE(CMSG_LOOT);
    FWD_TO_NODE(CMSG_LOOT_MONEY);
    FWD_TO_NODE(CMSG_LOOT_RELEASE);
    FWD_TO_NODE(CMSG_DUEL_ACCEPTED);
    FWD_TO_NODE(CMSG_DUEL_CANCELLED);
    FWD_TO_NODE(CMSG_MOUNTSPECIAL_ANIM);
    FWD_TO_NODE(CMSG_PET_SET_ACTION);
    FWD_TO_NODE(CMSG_PET_ACTION);
    FWD_TO_NODE(CMSG_PET_ABANDON);
    FWD_TO_NODE(CMSG_PET_RENAME);
    FWD_TO_NODE(CMSG_GOSSIP_HELLO);
    FWD_TO_NODE(CMSG_GOSSIP_SELECT_OPTION);
    FWD_TO_NODE(CMSG_QUESTGIVER_STATUS_QUERY);
    FWD_TO_NODE(CMSG_QUESTGIVER_HELLO);
    FWD_TO_NODE(CMSG_QUESTGIVER_QUERY_QUEST);
    FWD_TO_NODE(CMSG_QUESTGIVER_QUEST_AUTOLAUNCH);
    FWD_TO_NODE(CMSG_QUESTGIVER_ACCEPT_QUEST);
    FWD_TO_NODE(CMSG_QUESTGIVER_COMPLETE_QUEST);
    FWD_TO_NODE(CMSG_QUESTGIVER_REQUEST_REWARD);
    FWD_TO_NODE(CMSG_QUESTGIVER_CHOOSE_REWARD);
    FWD_TO_NODE(CMSG_QUESTGIVER_CANCEL);
    FWD_TO_NODE(CMSG_QUESTLOG_SWAP_QUEST);
    FWD_TO_NODE(CMSG_QUESTLOG_REMOVE_QUEST);
    FWD_TO_NODE(CMSG_QUEST_CONFIRM_ACCEPT);
    FWD_TO_NODE(CMSG_PUSHQUESTTOPARTY);
    FWD_TO_NODE(CMSG_LIST_INVENTORY);
    FWD_TO_NODE(CMSG_SELL_ITEM);
    FWD_TO_NODE(CMSG_BUY_ITEM);
    FWD_TO_NODE(CMSG_BUY_ITEM_IN_SLOT);
    FWD_TO_NODE(CMSG_TAXINODE_STATUS_QUERY);
    FWD_TO_NODE(CMSG_TAXIQUERYAVAILABLENODES);
    FWD_TO_NODE(CMSG_ACTIVATETAXI);
    FWD_TO_NODE(CMSG_TRAINER_LIST);
    FWD_TO_NODE(CMSG_TRAINER_BUY_SPELL);
    FWD_TO_NODE(CMSG_BINDER_ACTIVATE);
    FWD_TO_NODE(CMSG_BANKER_ACTIVATE);
    FWD_TO_NODE(CMSG_BUY_BANK_SLOT);
    FWD_TO_NODE(CMSG_PETITION_SHOWLIST);
    FWD_TO_NODE(CMSG_PETITION_BUY);
    FWD_TO_NODE(CMSG_PETITION_SHOW_SIGNATURES);
    FWD_TO_NODE(CMSG_PETITION_SIGN);
    FWD_TO_NODE(MSG_PETITION_DECLINE);
    FWD_TO_NODE(CMSG_OFFER_PETITION);
    FWD_TO_NODE(CMSG_TURN_IN_PETITION);
    FWD_TO_NODE(CMSG_PETITION_QUERY);
    FWD_TO_NODE(CMSG_BUG);
    FWD_TO_NODE(CMSG_PLAYED_TIME);
    FWD_TO_NODE(CMSG_QUERY_TIME);
    FWD_TO_NODE(CMSG_RECLAIM_CORPSE);
    FWD_TO_NODE(CMSG_WRAP_ITEM);
    FWD_TO_NODE(MSG_MINIMAP_PING);
    FWD_TO_NODE(CMSG_SETSHEATHED);
    FWD_TO_NODE(CMSG_PET_CAST_SPELL);
    FWD_TO_NODE(CMSG_ZONEUPDATE);
    FWD_TO_NODE(CMSG_UNLEARN_SKILL);
    FWD_TO_NODE(MSG_CORPSE_QUERY);
    FWD_TO_NODE(CMSG_SPIRIT_HEALER_ACTIVATE);
    FWD_TO_NODE(CMSG_BATTLEFIELD_LIST);
    FWD_TO_NODE(CMSG_BATTLEFIELD_JOIN);
    FWD_TO_NODE(CMSG_ITEM_TEXT_QUERY);
    FWD_TO_NODE(CMSG_LEARN_TALENT);
    FWD_TO_NODE(CMSG_TOGGLE_PVP);
    FWD_TO_NODE(MSG_AUCTION_HELLO);
    FWD_TO_NODE(CMSG_AUCTION_LIST_OWNER_ITEMS);
    FWD_TO_NODE(CMSG_AUCTION_LIST_BIDDER_ITEMS);
    FWD_TO_NODE(CMSG_SET_AMMO);
    FWD_TO_NODE(CMSG_SET_ACTIVE_MOVER);
    FWD_TO_NODE(CMSG_PET_CANCEL_AURA);
    FWD_TO_NODE(CMSG_CANCEL_AUTO_REPEAT_SPELL);
    FWD_TO_NODE(MSG_LIST_STABLED_PETS);
    FWD_TO_NODE(CMSG_STABLE_PET);
    FWD_TO_NODE(CMSG_UNSTABLE_PET);
    FWD_TO_NODE(CMSG_BUY_STABLE_SLOT);
    FWD_TO_NODE(CMSG_STABLE_REVIVE_PET);
    FWD_TO_NODE(CMSG_STABLE_SWAP_PET);
    FWD_TO_NODE(MSG_QUEST_PUSH_RESULT);
    FWD_TO_NODE(CMSG_REQUEST_PET_INFO);
    FWD_TO_NODE(CMSG_FAR_SIGHT);
    FWD_TO_NODE(CMSG_AUTOSTORE_BANK_ITEM);
    FWD_TO_NODE(CMSG_AUTOBANK_ITEM);
    FWD_TO_NODE(CMSG_BUYBACK_ITEM);
    FWD_TO_NODE(CMSG_CANCEL_GROWTH_AURA);
    FWD_TO_NODE(CMSG_REPAIR_ITEM);
    FWD_TO_NODE(MSG_TALENT_WIPE_CONFIRM);
    FWD_TO_NODE(CMSG_SUMMON_RESPONSE);
    FWD_TO_NODE(CMSG_SELF_RES);
    FWD_TO_NODE(CMSG_TOGGLE_HELM);
    FWD_TO_NODE(CMSG_TOGGLE_CLOAK);
    FWD_TO_NODE(CMSG_SET_ACTIONBAR_TOGGLES);
    FWD_TO_NODE(MSG_PETITION_RENAME);
    FWD_TO_NODE(CMSG_BATTLEFIELD_STATUS);
    FWD_TO_NODE(MSG_INSPECT_HONOR_STATS);
    FWD_TO_NODE(CMSG_BATTLEMASTER_HELLO);
    FWD_TO_NODE(MSG_PVP_LOG_DATA);
    FWD_TO_NODE(CMSG_LEAVE_BATTLEFIELD);
    FWD_TO_NODE(CMSG_AREA_SPIRIT_HEALER_QUERY);
    FWD_TO_NODE(CMSG_AREA_SPIRIT_HEALER_QUEUE);
    FWD_TO_NODE(MSG_BATTLEGROUND_PLAYER_POSITIONS);
    FWD_TO_NODE(CMSG_PET_STOP_ATTACK);
    FWD_TO_NODE(CMSG_PET_UNLEARN);
    FWD_TO_NODE(CMSG_PET_SPELL_AUTOCAST);
    FWD_TO_NODE(CMSG_ACTIVATETAXIEXPRESS);
    FWD_TO_NODE(CMSG_SET_FACTION_INACTIVE);
    FWD_TO_NODE(CMSG_SET_WATCHED_FACTION);

    // World opcodes
    FWD_TO_NODE(MSG_MOVE_WORLDPORT_ACK);
    FWD_TO_NODE(CMSG_MESSAGECHAT);

    /* Actions are handled master-side.
    * But we need to check if the player has the item/spell he wants to add as action button
    * So the opcode is handled by Node, and then forwarded to Master
    */
    FWD_TO_NODE(CMSG_SET_ACTION_BUTTON);

#define MASTER_OPCODE(opc) mMasterOpcode.insert(opc)
    // Social
    MASTER_OPCODE(CMSG_FRIEND_LIST);
    MASTER_OPCODE(CMSG_ADD_FRIEND);
    MASTER_OPCODE(CMSG_DEL_FRIEND);
    MASTER_OPCODE(CMSG_ADD_IGNORE);
    MASTER_OPCODE(CMSG_DEL_IGNORE);

    // Server cache query
    MASTER_OPCODE(CMSG_NAME_QUERY);
    MASTER_OPCODE(CMSG_PET_NAME_QUERY);

    // Mails
    MASTER_OPCODE(MSG_QUERY_NEXT_MAIL_TIME);

    // Chat
    MASTER_OPCODE(CMSG_MESSAGECHAT);

    // Channels
    MASTER_OPCODE(CMSG_JOIN_CHANNEL);
    MASTER_OPCODE(CMSG_LEAVE_CHANNEL);
    MASTER_OPCODE(CMSG_CHANNEL_LIST);
    MASTER_OPCODE(CMSG_CHANNEL_PASSWORD);
    MASTER_OPCODE(CMSG_CHANNEL_SET_OWNER);
    MASTER_OPCODE(CMSG_CHANNEL_OWNER);
    MASTER_OPCODE(CMSG_CHANNEL_MODERATOR);
    MASTER_OPCODE(CMSG_CHANNEL_UNMODERATOR);
    MASTER_OPCODE(CMSG_CHANNEL_MUTE);
    MASTER_OPCODE(CMSG_CHANNEL_UNMUTE);
    MASTER_OPCODE(CMSG_CHANNEL_INVITE);
    MASTER_OPCODE(CMSG_CHANNEL_KICK);
    MASTER_OPCODE(CMSG_CHANNEL_BAN);
    MASTER_OPCODE(CMSG_CHANNEL_UNBAN);
    MASTER_OPCODE(CMSG_CHANNEL_ANNOUNCEMENTS);
    MASTER_OPCODE(CMSG_CHANNEL_MODERATE);
}
